package com.zyl.Ecs.common.domain.auth.ext;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zyl.Ecs.common.domain.auth.bean.Account;
import com.zyl.Ecs.common.domain.auth.vo.AccountVO;
import com.zyl.Ecs.common.utils.CUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;

import java.util.List;

/**
 * @version v1.0
 * @ProjectName: Ecs
 * @Package: com.zyl.Ecs.auth.domain.dto
 * @ClassName: AccountDto
 * @Description TODO (用户扩展类)
 * @Author 翟玉龙
 * @Date 2024/12/4-16:57
 */
@Data
@SuperBuilder
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(value = "base_account")
@Accessors(chain = true)
public class AccountExt extends Account {

    /**
     * 用户包含的角色id列表（入参）
     */
    @TableField(exist = false)
    private List<Integer> roleIds;

    /**
     * 用户包含的所有角色（出参）
     */
    @TableField(exist = false)
    private List<RoleExt> roles;


    public static AccountExt toExt(Account account) {
        return CUtil.copyBean(account, AccountExt.class);
    }

    public static AccountExt toExt(AccountVO accountVO) {
        return AccountExt.builder()
                .id(accountVO.getId())
                .status(accountVO.getStatus())
                .username(accountVO.getUsername())
                .password(accountVO.getPassword())
                .roleIds(accountVO.getRoleIds())
                .telephone(accountVO.getTelephone())
                .build();
    }
}
